import datetime
from pydantic import BaseModel, Field

class CreditBase(BaseModel):
    balance: int = Field(ge=0)

class CreditUpdate(BaseModel):
    balance: int = Field(ge=0) # Specifically for admin to set a balance

class Credit(CreditBase):
    user_id: int

    class Config:
        from_attributes = True

class CreditLogBase(BaseModel):
    amount: int
    reason: str | None = None
    operator_id: int | None = None

class CreditLogCreate(CreditLogBase):
    user_id: int # Must be specified on creation

class CreditLog(CreditLogBase):
    id: int
    user_id: int
    created_at: datetime.datetime

    class Config:
        from_attributes = True
